﻿Imports Newtonsoft.Json

''' <summary>
''' Enumeration to make keeping track of Assignment Priority (Low, Medium, High) easier
''' </summary>
''' <remarks></remarks>
Public Enum AssignmentPriority
    low = 0
    medium = 1
    high = 2
End Enum


''' <summary>
''' Class to keep track of Assignments
''' </summary>
''' <remarks></remarks>
<JsonObject(MemberSerialization.OptOut)> _
Public Class Assignment
    Public Property name As String
    Public Property priority As AssignmentPriority
    Public Property starred As Boolean ' Planned for RC 1.2
    Public Property startDate As Date
    Public Property endDate As Date
    Public Property complete As Boolean
    Public Property grade As Double ' Planned for RC 2.0
    Public Property worth As Double ' Planned for RC 2.0
    Public Property extraCredit As Boolean ' Planned for RC 2.0
    Public Property counted As Boolean ' Planned for RC 2.0
    Public Property notes As String
    Public Property steps As List(Of AssignmentStep)
    Public Property guid As String

    ' This essentially says "Hey, don't serialize/deserialize me"
    <JsonIgnore()> _
    Public Property parent As Course

    ' Lazy James is lazy at programming and passes data around in weird ways
    <JsonIgnore()> _
    Public Shared courseList As List(Of Course)
    <JsonIgnore()> _
    Public Shared assignmentList As List(Of Assignment)
    <JsonIgnore()> _
    Public Shared assignmentEditMenu As MenuItem
    <JsonIgnore()> _
    Public Shared assignmentDeleteMenu As MenuItem

    Public Event created(ByRef e As Assignment)
    Public Event changedParentCourseName(ByRef e As Assignment)

    Public Sub New()
        ' set object's GUID. Add checking here at some point?
        guid = String.Concat("_", System.Guid.NewGuid().ToString("N"))
        name = "New Task"
        priority = AssignmentPriority.low
        starred = False
        startDate = Today
        endDate = Today.AddDays(1)
        complete = False
        grade = 0
        worth = 0
        extraCredit = False
        counted = True
        notes = ""
        steps = New List(Of AssignmentStep)
    End Sub

    Public Sub Edit()
        Dim form As New EditAssignment(Me)
        form.ShowDialog()
        If form.Response = MessageBoxResult.OK Then
            ' Remove from old course
            parent.assignments.Remove(Me)
            ' Set parent property to proper course
            parent = courseList(form.assignmentCourse.SelectedIndex)
            ' Add to new course
            parent.assignments.Add(Me)

            form.Close()
        Else
            ' User decided "No, I don't want a new assignment"
            form.Close()
        End If
    End Sub

    Public Sub Create()
        If courseList.Count > 0 Then
            Dim form As New EditAssignment(Me)
            form.ShowDialog()
            If form.Response = MessageBoxResult.OK Then
                ' Set parent property to proper course
                parent = courseList(form.assignmentCourse.SelectedIndex)
                ' Add to proper course (which adds to myData as well)
                parent.assignments.Add(Me)
                ' Add to the assignment pool
                RaiseEvent created(Me)
            End If
            form.Close()
        Else
            MessageBox.Show("Sorry, you must have at least one course before creating a class!")
        End If
    End Sub

    Public Sub Delete()
        parent.assignments.Remove(Me)
    End Sub

    Public Sub callChangedParentCourseName()
        RaiseEvent changedParentCourseName(Me)
    End Sub
End Class